package com.richman.view;



import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

import com.richman.controller.NegativeRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.utils.Common;
import com.richman.utils.GameTimeAsc;
import com.richman.view.BetLogPane;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class BetAlreadyPane extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8L;
	
	private  Vector<String[]> detailsData = new Vector<String[]>();
	
	public Vector<Event> gameDetailsVec = new Vector<Event>(); 
	
	
	public RebetWindow rebetWnd = new RebetWindow();
	
	//BrowserPanel bp = new BrowserPanel();
	
	private JPopupMenu m_tablepopupMenu;

    
    JMenuItem rebetMenuItem = null;
    
	public int selectedRow = -1;
	
	
	MyTableModel tableMode = new MyTableModel();
	
	private  ReadWriteLock betDvaluesLock = new ReentrantReadWriteLock(); 

	Vector<BetAdyData> gamedetailsLocal = new Vector<BetAdyData>();
	
	private  ReadWriteLock gamedetailsLock = new ReentrantReadWriteLock(); 
	
	
	JTable table = null;

	/**
	 * Create the panel.
	 */
	public BetAlreadyPane() {
		setLayout(new BorderLayout(0, 0));

		JPanel funBtnPane = new JPanel();
		
		JButton cleanButton = new JButton("清空数据");
		cleanButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int n = JOptionPane.showConfirmDialog(null, "确认要清空数据吗?", "清空数据",
						JOptionPane.YES_NO_OPTION);
				if (n == JOptionPane.YES_OPTION && NegativeRatioClient.betCtrMng != null) {
					NegativeRatioClient.betCtrMng.clearBetAdyData();
				}
				
			}
		});
		
		cleanButton.setBounds(20, 10, 60, 20);
		
		funBtnPane.add(cleanButton);
		
		add(funBtnPane, BorderLayout.NORTH);
		
		
	    table = new JTable(tableMode);
	    
	    table.getColumnModel().getColumn(0).setPreferredWidth(30);
	    
	    table.getColumnModel().getColumn(2).setPreferredWidth(120);
	    table.getColumnModel().getColumn(3).setPreferredWidth(130);
	    table.getColumnModel().getColumn(4).setPreferredWidth(200);
	    table.getColumnModel().getColumn(5).setPreferredWidth(100);
	    
	    
	    table.getColumnModel().getColumn(8).setPreferredWidth(180);
	    table.getColumnModel().getColumn(11).setPreferredWidth(180);
	    
	   
	    
	    table.setRowHeight(30);
	    
	    table.setFont(new java.awt.Font("黑体", Font.PLAIN, 15));
		
		
		JScrollPane scrollPane = new JScrollPane(table);
		add(scrollPane, BorderLayout.CENTER);

		table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
     	       //判断是否为鼠标的BUTTON3按钮，BUTTON3为鼠标右键  
     	       if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
     	          
     	    	 
     	    	   
     	           //弹出菜单  
     	         selectedRow = table.rowAtPoint(evt.getPoint());
     	           
     	         if(selectedRow == -1) {
     	        	 return;
     	         }
     	         
     	         
     	         String ps38betres = detailsData.elementAt(selectedRow)[13];
     	         
     	         if(ps38betres.contains("失败")) {
     	        	m_tablepopupMenu.show(table, evt.getX(), evt.getY());
     	         }

     	       }
            }  
        });
		
		

		
		
	    m_tablepopupMenu = new JPopupMenu();
	    rebetMenuItem = new JMenuItem();
	    rebetMenuItem.setText("手动补单");
	    rebetMenuItem.addActionListener(new java.awt.event.ActionListener() {  
            public void actionPerformed(java.awt.event.ActionEvent evt) {  
                //该操作需要做的事  
            	
            	try{
            		
            		boolean delSuc = false;
            		
            		rebetWnd.setgame(detailsData.elementAt(selectedRow));
            		
            		rebetWnd.setVisible(true);

            		if(delSuc == true) {
            			JOptionPane.showMessageDialog(null, "已解除匹配", "已解除匹配", JOptionPane.DEFAULT_OPTION);
            		}

            	}catch(Exception e){
            		e.printStackTrace();
            	}

            }  
        });
		

		
	    m_tablepopupMenu.add(rebetMenuItem);

	}
	
	
	
	public void updateBetAdyTable(Vector<BetAdyData> gamedetails){
		
		try{
			gamedetailsLock.writeLock().lock();
			if(gamedetailsLocal.size() != 0)
			{
				gamedetailsLocal.clear();
			}
			for(int i = 0; i < gamedetails.size(); i++) {
				BetAdyData game = gamedetails.elementAt(i);
				gamedetailsLocal.add(game);
			}
			
			gamedetailsLock.writeLock().unlock();
				
			if(detailsData.size() != 0){
				detailsData.clear();
			}
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			int betcount = gamedetails.size();
			
			for(int i = 0; i < gamedetails.size(); i++) {
				
				BetAdyData game = gamedetails.elementAt(i);
				
				if(!Common.isNum(game.ps38betgold)) {
					continue;
				}
				
				String hgbetres = "";
				
				if(game.hgbetres.equals("1")) {
					hgbetres = "成功";
				}else if(game.hgbetres.equals("2")) {
					hgbetres = "确认成功";
				}else if(game.hgbetres.equals("0")) {
					hgbetres = "注单待确认";
				}else if(game.hgbetres.equals("-1")) {
					hgbetres = "超过信用额度";
				}else if(game.hgbetres.equals("-2")) {
					hgbetres = "失败 ";
				}else if(game.hgbetres.equals("-3")) {
					hgbetres = "注单取消，投注失败 ";
				}else if(game.hgbetres.equals("-4")) {
					hgbetres = "股东限额，投注失败";
				}else {
					hgbetres = game.hgbetres;
				}
				
				
				String ps38betres = "";
				
				if(game.ps38betres.equals("")) {
					ps38betres = "失败";
				}else if(game.ps38betres.equals("2")) {
					ps38betres = "确认成功";
				}else if(game.ps38betres.equals("1")) {
					ps38betres = "成功";
				}else if(game.ps38betres.equals("0")) {
					ps38betres = "注单待确认";
				}else if(game.ps38betres.equals("-3")) {
					ps38betres = "注单取消，投注失败";
				}else if(game.ps38betres.equals("-4")) {
					ps38betres = "注单暂时无法确认,请人工确认";
				}else {
					ps38betres = game.ps38betres;
				}
				
				
				if(game.ps38rebetflag != null && game.ps38rebetflag.equals("1")) {
					ps38betres = "补单-" + ps38betres;
				}
				
				
				int totalBetTimes = 0;
				int totalBetGold = 0;
				for(int j = 0; j < gamedetails.size(); j++) {
					BetAdyData gameTmp = gamedetails.elementAt(j);
					if(!Common.isNum(gameTmp.ps38betgold)) {
						continue;
					}
					if(gameTmp.teams.equals(game.teams)
					&& gameTmp.bettype.equals(game.bettype)
					&& gameTmp.time.equals(game.time)) {
						totalBetTimes++;
						
						totalBetGold += Integer.parseInt(gameTmp.ps38betgold);
					}
				}
				
				
				//{ "序号", "联赛", "时间", "球队", "投注类型", "投注盘口","合并赔率", "皇冠注单", "皇冠金额", "皇冠投注时间","皇冠结果", "PS38注单", "PS38金额 ", "PS38投注时间 ", "PS38结果"};
				String[] item = {
									Integer.toString(betcount - i),//0
									game.currenttime,
									game.league,
									game.time,
									game.teams,
									game.bettype,//5
									game.betpankou,

									game.ps38bettype,
									game.ps38betgold,
									ps38betres,
									game.score,//14
									game.websitetype,//15
									Integer.toString(totalBetTimes) + "/" + Integer.toString(totalBetGold),
									game.ps38eventid,
									game.hgeventid,//[18]
									game.hgps38,//[19]
									game.result,
									game.danshipankou,//[21]
									game.danshidaxiao,//[22]
									""
									};
				
				detailsData.add(0, item);
				
			}
			
			//计算
			
			for(int i= 0;i <detailsData.size();i++ ) {
				for(int j = 0; j < BetLogPane.limitStr.size();j++) {
					String tmp = BetLogPane.limitStr.get(detailsData.elementAt(i)[4]+ detailsData.elementAt(i)[5]);
					if(tmp!=null) {
						detailsData.elementAt(i)[23] = tmp;
					}
				}
			}
			
			Comparator<String[]> cmp = new GameTimeAsc();
			
			Collections.sort(detailsData , cmp);
			
			//constructBetDvalue();

			setOneRowBackgroundColor();
			
			tableMode.updateTable();

			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	
	
	
	
	
	
	
	
	private void constructBetDvalue() {
		
		
		try {
			
			betDvaluesLock.writeLock().lock();
			
			Vector<String> parsealready = new Vector<String>();
			
			
			if(NegativeRatioClient.betCtrMng.betDvalues != null) {
				NegativeRatioClient.betCtrMng.betDvalues.clear();
			}
			
			
			double maxdvalue = NegativeRatioClient.mainWnd.getmaxdvalue();
			
			SimpleDateFormat dfGameTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			SimpleDateFormat dfCurrentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			for(int i = 0; i < detailsData.size(); i++) {
				
				String[] item = detailsData.elementAt(i);
				
				if(Common.isNum(item[7])) {
					double ratio = Double.parseDouble(item[7]);
					if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
						//投注赔率不超过利润设置则不进行统计
						continue;
	    				
					}
				}
				
				
				if(parsealready.contains(item[18])) {//已经分析过这场球赛
					continue;
				}
				
				
				parsealready.add(item[18]);
				
				
				boolean bfirstpankou = true;
				
				String sfirstpankou = "";
				
				for(int j = detailsData.size()-1; j >=0; j--) {
					
					
					String[] item1 = detailsData.elementAt(j);
					
					if(Common.isNum(item1[7])) {
						double ratio = Double.parseDouble(item1[7]);
						if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
							//投注赔率不超过利润设置则不进行统计
							continue;
		    				
						}
					}
					
					String beforeGameTime = "";
					try {
						long tmp1 = dfGameTime.parse(item1[3]).getTime() - dfCurrentTime.parse(item1[1]).getTime();
						tmp1 = tmp1/1000/60;
						beforeGameTime = Long.toString(tmp1);
					}catch(Exception e) {
						
					}
					
					int beforeGameTimeFilter = NegativeRatioClient.mainWnd.getbeforeGameTimeFilter();
					if( Integer.parseInt(beforeGameTime) >beforeGameTimeFilter ) {
						continue; //过滤超出时间范围的注单
					}
					
					if(item1[18].equals(item[18])) {
						
						if(bfirstpankou == true) {						
							
							bfirstpankou = false;
							sfirstpankou = item1[6];
							
							BetDvalue bdvalue = new BetDvalue();
							
							
							bdvalue.time = item1[3];
							bdvalue.league = item1[2];
							bdvalue.team = item1[4];
							bdvalue.betscore = item1[14];
							if(item1[5].contains("让球")) {
								bdvalue.rqbetpankou = item1[6];
								bdvalue.rqbettype = item1[5];
																								
								if(item1[19].equals("1")) {
									if(bdvalue.rqhgps38times==0) {
										bdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
									}else {
										bdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
									}
									bdvalue.rqhgps38times++;
								}else if(item1[19].equals("2")) {									
									if(bdvalue.rqps38hgtimes==0) {
										bdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}else {
										bdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									
									bdvalue.rqps38hgtimes++;
								}
							}else {
								bdvalue.dxbetpankou = item1[6];								
								bdvalue.dxbettype = item1[5];								
								if(item1[19].equals("1")) {									
									if(bdvalue.dxhgps38times==0) {
										bdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}else {
										bdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									
									bdvalue.dxhgps38times++;
								}else if(item1[19].equals("2")) {
									
									if(bdvalue.dxps38hgtimes==0) {
										bdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
									}else {
										bdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									bdvalue.dxps38hgtimes++;
								}
								
							}
							
							
							
							
							bdvalue.eventid = item1[18];
							bdvalue.result = item1[20];
							
							bdvalue.danshipankou = item1[21];
							bdvalue.danshidaxiao = item1[22];
							
							NegativeRatioClient.betCtrMng.betDvalues.add(bdvalue);
							
							

						}else {
							
							
							if(item1[5].contains("让球")) {
								
								String rqfirstpankou = "";
								boolean first = true;
								boolean find = false;
								
								for(int k = 0; k < NegativeRatioClient.betCtrMng.betDvalues.size(); k++) {
									
									BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betDvalues.elementAt(k);
									
									if(bdvalue.eventid.equals(item1[18]) && 
											bdvalue.rqbettype.length() >=3 &&
									   bdvalue.rqbettype.substring(2).equals(item1[5].substring(2))
									   
									   //DaShuiClient.betCtrMng.betDvalues.elementAt(k).bettype.substring(2).equals(item1[5].substring(2)) &&
									   //Math.abs(Double.parseDouble(DaShuiClient.betCtrMng.betDvalues.elementAt(k).firstpankou) - Double.parseDouble(item1[6])) <= maxdvalue) 
											){
										
										if(first == true) {
											rqfirstpankou = bdvalue.rqbetpankou;
											first = false;
											
										}
										
										
										if( bdvalue.rqbettype.equals(item1[5])&&
												bdvalue.betscore.equals(item1[14]) &&
												   
												   Math.abs(Double.parseDouble(bdvalue.rqbetpankou) - Double.parseDouble(item1[6])) < 0.01) {
											
//											if(item1[19].equals("1")) {
//												bdvalue.rqhgps38times++;
//											}else if(item1[19].equals("2")) {
//												bdvalue.rqps38hgtimes++;
//											}
											
											if(item1[19].equals("1")) {
												if(bdvalue.rqhgps38times==0) {
													bdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}else {
													bdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
												}
												bdvalue.rqhgps38times++;
											}else if(item1[19].equals("2")) {									
												if(bdvalue.rqps38hgtimes==0) {
													bdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}else {
													bdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}
												
												bdvalue.rqps38hgtimes++;
											}
											

											find = true;
											
											break;
											
										}
										

										
									}
									
								}
								
								boolean newtype = false;
								
								if(rqfirstpankou.equals("")) {
									newtype = true;
								}
								
								if( newtype ||
										(find == false && Math.abs(Double.parseDouble(rqfirstpankou) - Double.parseDouble(item1[6])) <= maxdvalue)) {
									BetDvalue newbdvalue = new BetDvalue();
									newbdvalue.betscore = item1[14];
									newbdvalue.rqbettype = item1[5];
									newbdvalue.rqbetpankou = item1[6];
									newbdvalue.eventid = item1[18];
//									if(item1[19].equals("1")) {
//										newbdvalue.rqhgps38times++;
//									}else if(item1[19].equals("2")) {
//										newbdvalue.rqps38hgtimes++;
//									}
									
									if(item1[19].equals("1")) {
										if(newbdvalue.rqhgps38times==0) {
											newbdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}else {
											newbdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}
										newbdvalue.rqhgps38times++;
									}else if(item1[19].equals("2")) {									
										if(newbdvalue.rqps38hgtimes==0) {
											newbdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}else {
											newbdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}
										
										newbdvalue.rqps38hgtimes++;
									}
									
									NegativeRatioClient.betCtrMng.betDvalues.add(newbdvalue);

								}
								
							}else {
								
								String dxfirstpankou = "";
								boolean first = true;
								boolean find = false;
								
								for(int k = 0; k < NegativeRatioClient.betCtrMng.betDvalues.size(); k++) {
									
									BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betDvalues.elementAt(k);
									
									if(bdvalue.eventid.equals(item1[18]) && 
											bdvalue.dxbettype.length() >=3 &&
										bdvalue.dxbettype.substring(2).equals(item1[5].substring(2)) 
									   
									   
											){
										
										if(first == true) {
											dxfirstpankou = bdvalue.dxbetpankou;
											first = false;
										}
										
										if( bdvalue.dxbettype.equals(item1[5]) &&
												bdvalue.betscore.equals(item1[14]) &&
											Math.abs(Double.parseDouble(bdvalue.dxbetpankou) - Double.parseDouble(item1[6])) < 0.01) {
//											if(item1[19].equals("1")) {
//												bdvalue.dxhgps38times++;
//											}else if(item1[19].equals("2")) {
//												bdvalue.dxps38hgtimes++;
//											}
											
											if(item1[19].equals("1")) {									
												if(bdvalue.dxhgps38times==0) {
													bdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}else {
													bdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}
												
												bdvalue.dxhgps38times++;
											}else if(item1[19].equals("2")) {
												
												if(bdvalue.dxps38hgtimes==0) {
													bdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}else {
													bdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
												}
												bdvalue.dxps38hgtimes++;
											}
											
											find = true;
											
											break;
											
										}
										
										

										
										
										
									}
									
									
									

									
								}
								
								
								boolean newtype = false;
								
								if(dxfirstpankou.equals("")) {
									newtype = true;
								}
								
								
								
								
								if(newtype ||
										(find == false && Math.abs(Double.parseDouble(dxfirstpankou) - Double.parseDouble(item1[6])) <= maxdvalue)) {
									BetDvalue newbdvalue = new BetDvalue();
									newbdvalue.betscore = item1[14];
									newbdvalue.dxbettype = item1[5];
									newbdvalue.dxbetpankou = item1[6];
									newbdvalue.eventid = item1[18];
//									if(item1[19].equals("1")) {
//										newbdvalue.dxhgps38times++;
//									}else if(item1[19].equals("2")) {
//										newbdvalue.dxps38hgtimes++;
//									}
									
									if(item1[19].equals("1")) {									
										if(newbdvalue.dxhgps38times==0) {
											newbdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}else {
											newbdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}
										
										newbdvalue.dxhgps38times++;
									}else if(item1[19].equals("2")) {										
										if(newbdvalue.dxps38hgtimes==0) {
											newbdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
										}else {
											newbdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}
										newbdvalue.dxps38hgtimes++;
									}
									
									NegativeRatioClient.betCtrMng.betDvalues.add(newbdvalue);

								}
								
								
								
							}
							
							
							

							
						}
						
					}
					
				}
				
				//todo  fill whole bdvalue
				
				int wholehgps38times = 0;
				int wholeps38hgtimes = 0;
				
				int dxwholehgps38times = 0;
				int dxwholeps38hgtimes = 0;
				
				String rqdvalue = "";
				String dxdvalue = "";
				
				for(int k = 0; k < NegativeRatioClient.betCtrMng.betDvalues.size(); k++) {
					
					BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betDvalues.elementAt(k);
					
					if(bdvalue.eventid.equals(item[18]) && 
						bdvalue.rqbettype.contains("让球") 
					   ){
						

						wholehgps38times += bdvalue.rqhgps38times;
						wholeps38hgtimes += bdvalue.rqps38hgtimes;
						
						
						
						
					}
					
					if(bdvalue.eventid.equals(item[18]) && 
							bdvalue.dxbettype.contains("大小") 
						   ){
							

						dxwholehgps38times += bdvalue.dxhgps38times;
						dxwholeps38hgtimes += bdvalue.dxps38hgtimes;							
						}				
				}
				
				

				if(wholehgps38times < wholeps38hgtimes) {
					
					rqdvalue = item[4].split("-vs-")[1] + "/" + Integer.toString(wholeps38hgtimes - wholehgps38times);
					
					for(int kk = 0; kk < detailsData.size(); kk++) {
						String currentStr = detailsData.elementAt(kk)[4] + detailsData.elementAt(kk)[5];
						String getStr = "";
						if(currentStr.contains(item[4] )  && currentStr.contains("让球")) {

							getStr = detailsData.elementAt(kk)[16];
							rqdvalue = item[4].split("-vs-")[1] + " " + getStr;
							break;
						}
					}
					
					
					
				}else {
					rqdvalue = item[4].split("-vs-")[0] + "/" + Integer.toString(wholehgps38times - wholeps38hgtimes);
					
					for(int kk = 0; kk < detailsData.size(); kk++) {
						String currentStr = detailsData.elementAt(kk)[4] + detailsData.elementAt(kk)[5];
						String getStr = "";
						if(currentStr.contains(item[4]) && currentStr.contains("让球") ) {
							getStr = detailsData.elementAt(kk)[16];
							rqdvalue = item[4].split("-vs-")[0] + " " + getStr;
							break;
						}
					}
					
				}
				
				
				

				if(dxwholehgps38times < dxwholeps38hgtimes) {
					
					dxdvalue = "小" + "/" + Integer.toString(dxwholeps38hgtimes - dxwholehgps38times);
					
					for(int kk = 0; kk < detailsData.size(); kk++) {
						String currentStr = detailsData.elementAt(kk)[4] + detailsData.elementAt(kk)[5];
						String getStr = "";
						if(currentStr.contains(item[4] ) && currentStr.contains("大小")) {
							getStr = detailsData.elementAt(kk)[16];
							dxdvalue = "小" + " " + getStr;
							break;
						}
					}
					
					
				}else {
					dxdvalue = "大" + "/" + Integer.toString(dxwholehgps38times -dxwholeps38hgtimes);
					
					for(int kk = 0; kk < detailsData.size(); kk++) {
						String currentStr = detailsData.elementAt(kk)[4] + detailsData.elementAt(kk)[5];
						String getStr = "";
						if(currentStr.contains(item[4] ) && currentStr.contains("大小")) {
							getStr = detailsData.elementAt(kk)[16];
							dxdvalue = "大" + " " + getStr;
							break;
						}
					}
					
				}
				

				

				
				BetDvalue bdvalue = new BetDvalue();
				boolean add = false;
				
				if(wholehgps38times != 0 || wholeps38hgtimes != 0) {
					
					bdvalue.rqdvalue = rqdvalue;
					add = true;
				}
				
				if(dxwholehgps38times != 0 || dxwholeps38hgtimes != 0) {
					
					bdvalue.dxdvalue = dxdvalue;
					add = true;
				}
				
				if(add == true) {
					NegativeRatioClient.betCtrMng.betDvalues.add(bdvalue);
				}
				
				
			}
			
			
			//服务器不投特殊投注
			
			Vector<BetDvalue> bets = new Vector<BetDvalue>();
			
			for(int i = 0;i < NegativeRatioClient.betCtrMng.betDvalues.size();i++) {
				bets.add(NegativeRatioClient.betCtrMng.betDvalues.elementAt(i));
			}
			
			Vector<BetDvalue> bets1 = new Vector<BetDvalue>();
			
			for(int i = 0;i < NegativeRatioClient.betCtrMng.betDvalues.size();i++) {
				bets1.add(NegativeRatioClient.betCtrMng.betDvalues.elementAt(i));
			}
			
			NegativeRatioClient.mainWnd.updateBetDvalueTable(bets);
			
			NegativeRatioClient.mainWnd.updateBetDvalueTable1(bets1);
			
//			for(int i =0; i < SpecialServer.betCtrMng.betDvalues.size();i++ ) {
//				System.out.println(SpecialServer.betCtrMng.betDvalues.elementAt(i).tostring());
//				
//			}
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		
		betDvaluesLock.writeLock().unlock();

	}
	
	
	
	public Vector<BetDvalue> getBetDvalus(){
		Vector<BetDvalue> vec = new Vector<BetDvalue>();
		
		betDvaluesLock.readLock().lock();
		
		
		
		for(int i = 0; i < NegativeRatioClient.betCtrMng.betDvalues.size(); i++){
		
			
			
			
			vec.add(NegativeRatioClient.betCtrMng.betDvalues.elementAt(i));
			

			
		}
		
		betDvaluesLock.readLock().unlock();
		
		return vec;
	}
	
	
	public Vector<BetAdyData> getBetAdyDatas(){
		
		Vector<BetAdyData> vec = new Vector<BetAdyData>();
		gamedetailsLock.readLock().lock();
		for(int i = 0; i < gamedetailsLocal.size(); i++){
			vec.add(gamedetailsLocal.elementAt(i));
		}		
		gamedetailsLock.readLock().unlock();		
		return vec;
	}
	
	
	
	
    public void setOneRowBackgroundColor() {
    	

    	
        try {  
        	
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
            	
            	
  
                public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {  

                	
                    if (row%2==1) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
            };  
            
            
            DefaultTableCellRenderer resRender = new DefaultTableCellRenderer() {   

                public void setValue(Object value) { //重写setValue方法，从而可以动态设置列单元字体颜色   

                   
                	String str = value.toString();
                	
    				
    				
    				if(str.contains("成功")){
    					
    					setBackground(Color.GREEN);

    				}else if(str.contains("失败")){    	
    					setBackground(Color.red);
    				}else {
    					setBackground(Color.yellow);
    				}
    				
    				
    				setForeground(Color.BLACK);
    					
    				setText((value == null) ? "" : str);
    				
    				 setHorizontalAlignment(JLabel.CENTER);

                }   

            };
            
            
            
            
            
            DefaultTableCellRenderer ratioRender = new DefaultTableCellRenderer() {   

                public void setValue(Object value) { //重写setValue方法，从而可以动态设置列单元字体颜色   

                   
                	String str = value.toString();
                	
                	
                	setForeground(Color.BLACK);
                	
    				if(Common.isNum(str)) {
    					double ratio = Double.parseDouble(str);
    					if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
    						setForeground(Color.red);
    	    				
    					}
    				}
    				
    				//setBackground(new Color(246,246,246)); 
    				
    				
    					
    				setText((value == null) ? "" : str);
    				
    				 setHorizontalAlignment(JLabel.CENTER);

                } 
                
                
                public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {  

                	
                    if (row%2==1) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
                
                
                

            }; 
            
            
            
            
            
            
            
            int columnCount = table.getColumnCount();  
            for (int i = 0; i < columnCount; i++) {  
            	
            	String columnname = table.getColumnName(i);
            	
            	if(columnname.equals("皇冠结果") || columnname.equals("结果")) {
            		table.getColumn(columnname).setCellRenderer(resRender);
            	//	continue;
            	}else if(columnname.equals("合并赔率")){
            		table.getColumn(columnname).setCellRenderer(ratioRender);
            		
            	}else {
            		table.getColumn(columnname).setCellRenderer(tcr);
            	}
            	
            	
            }  
        } catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    
    }  
	
	
	
	

    public class MyTableModel extends AbstractTableModel  
    {  
        /**
		 * 
		 */
		private static final long serialVersionUID = 10086L;
		/* 
         * 这里和刚才一样，定义列名和每个数据的值 
         */  
        String[] columnNames =          
        	{ "序号", "时间", "联赛", "比赛时间", "球队", "投注类型", "投注盘口",  "注单", "金额 ",  "结果", "投注比分","网址","手数/总金额"};

  
        /** 
         * 构造方法，初始化二维数组data对应的数据 
         */  
        public MyTableModel()  
        {  

        }  
  
        // 以下为继承自AbstractTableModle的方法，可以自定义  
        /** 
         * 得到列名 
         */  
        @Override  
        public String getColumnName(int column)  
        {  
            return columnNames[column];  
        }  
          
        /** 
         * 重写方法，得到表格列数 
         */  
        @Override  
        public int getColumnCount()  
        {  
            return columnNames.length;  
        }  
  
        /** 
         * 得到表格行数 
         */  
        @Override  
        public int getRowCount()  
        {         
	        if(null == detailsData){
	    		return 0;
	    	}
            return detailsData.size();  
        }  
  
        /** 
         * 得到数据所对应对象 
         */  
        @Override  
        public Object getValueAt(int rowIndex, int columnIndex)  
        {  
            //return data[rowIndex][columnIndex];
        	if(columnIndex==17) {
        		return detailsData.elementAt(rowIndex)[23];
        	}
        	return detailsData.elementAt(rowIndex)[columnIndex];
        }  
  
        /** 
         * 得到指定列的数据类型 
         */  
        @Override  
        public Class<?> getColumnClass(int columnIndex)  
        {  
        	
        	return String.class;
        	
//        	if(detailsData.size() == 0){
//        		return String.class;
//        	}
//
//            return detailsData.elementAt(0)[columnIndex].getClass();
        	
        }  
  
        /** 
         * 指定设置数据单元是否可编辑.这里设置"姓名","学号"不可编辑 
         */  
        @Override  
        public boolean isCellEditable(int rowIndex, int columnIndex)  
        {  
            return false;
        }  
          
        /** 
         * 如果数据单元为可编辑，则将编辑后的值替换原来的值 
         */  
        @Override  
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)  
        {  
            detailsData.elementAt(rowIndex)[columnIndex] = (String)aValue;  
            /*通知监听器数据单元数据已经改变*/  
            fireTableCellUpdated(rowIndex, columnIndex);  
        }  
        
        public void updateTable(){
        	fireTableDataChanged();
        }
        
  
    }  

}
